package com.lbb.simple.demo.activity

import android.view.View
import androidx.core.view.ViewCompat
import androidx.viewbinding.ViewBinding
import com.google.android.material.appbar.MaterialToolbar
import com.lbb.mvp.activity.BaseActivity
import com.lbb.simple.R
import com.lbb.utils.DisplayUtil
import com.lbb.utils.ThemeUtil


abstract class BaseActivity<B : ViewBinding> : BaseActivity<B>() {
    override fun setContentView(view: View?) {
        super.setContentView(view)

        val materialToolbar: MaterialToolbar? = findViewById(R.id.materialToolbar)

        materialToolbar?.let { toolbar ->
            toolbar.setPadding(0, DisplayUtil.getStatusBarHeight(), 0, 0)
            val p = toolbar.layoutParams
            p.height = DisplayUtil.getStatusBarHeight() + DisplayUtil.dp2px(50f)
            toolbar.layoutParams = p
            toolbar.setNavigationOnClickListener {
                onBackPressed()
            }
            toolbar.setNavigationIcon(R.drawable.ic_baseline_arrow_back_24)
            toolbar.navigationIcon?.setTint(
                ThemeUtil.getColor(
                    this,
                    R.attr.toolBarTextColor
                )
            )
            view?.let { it ->
                val v = ViewCompat.getWindowInsetsController(it)
                if (ThemeUtil.getBoolean(this, R.attr.isBlackStatus)) {
                    v?.isAppearanceLightStatusBars = true
                    v?.isAppearanceLightNavigationBars = true
                } else {
                    v?.isAppearanceLightStatusBars = false
                    v?.isAppearanceLightNavigationBars = false

                }
            }
        }
    }

}